package com.example.viewdemo

import com.example.viewdemo.tool.VersionUtils
import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }
    @Test
    fun testParseAndroidVersion() {
        // 正常场景
        val version = VersionUtils.parseAndroidVersion("Android OS 14")
        assertEquals(14, version)

        // 有后缀场景
        val version2 = VersionUtils.parseAndroidVersion("Android OS 14（某某版）")
        assertEquals(14, version2)
    }


}

class VersionUtilsTest {

    @Test
    fun `testParseAndroidVersion with valid version number`() {
        // Arrange
        val displayName = "Android OS 14"

        // Act
        val version = VersionUtils.parseAndroidVersion(displayName)

        // Assert
        assertEquals(14, version)
    }

    @Test
    fun `testParseAndroidVersion with version number and suffix`() {
        // Arrange
        val displayName = "Android OS 14（某某版）"

        // Act
        val version = VersionUtils.parseAndroidVersion(displayName)

        // Assert
        assertEquals(14, version)
    }

    @Test
    fun `testParseAndroidVersion with no version number`() {
        // Arrange
        val displayName = "Android OS"

        // Act
        val version = VersionUtils.parseAndroidVersion(displayName)

        // Assert
        assertEquals(-1, version)
    }

    @Test
    fun `testParseAndroidVersion with empty string`() {
        // Arrange
        val displayName = ""

        // Act
        val version = VersionUtils.parseAndroidVersion(displayName)

        // Assert
        assertEquals(-1, version)
    }

    @Test
    fun `testParseAndroidVersion with null input`() {
        // Arrange
        val displayName: String? = null

        // Act
        val version = VersionUtils.parseAndroidVersion(displayName ?: "")

        // Assert
        assertEquals(-1, version)
    }
}